package misc;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

import database.database_auth;

/** misc functions that could not be categories **/
public class misc {

	/**
	 * generate a unique list of HashMaps
	 * that have unique value@key
	 * 
	 * STATUS: ROUGHLY TESTED
	**/
	public ArrayList unique(ArrayList list, String key)
	{
		ArrayList<Object> result = new ArrayList<Object>();

		int LENGTH = list.size();
		for(int counter = 0;counter < LENGTH;counter++)
		{
			HashMap item = (HashMap) list.get(counter);
			
			for(int counter1 = 0;counter1 < LENGTH;counter1++)
			{
				HashMap item1 = (HashMap) list.get(counter);
				if(item.get(key).equals(item1.get(key)))
				{
					if((result.size() == 0))
					{
						result.add(item.get(key));
					}
					else
					{
						if(!result.contains(item1.get(key)))
						{
							result.add(item.get(key));
						}
					}
				}
			}
		}
		
		return result;
	}

	/** checks if THIS element exists in a HashMap-LIST of elements (can be numbers, strings, Objects) **/
	public boolean exists( HashMap LIST, Object THIS ) 
	{
		boolean result = false;
		Set<String> KEYSET = LIST.keySet();
		for ( Object OBJECT : KEYSET )
		{
			System.out.println(LIST.get(OBJECT));

			if(LIST.get(OBJECT) == THIS)
			{
				result = true;
			}
			else
			{
				result = false;
			}
		}
		
		return result; 
	}
	
	/** checks if element is empty/undefined (can be numbers, strings, Objects) **/
	public boolean empty(Object OBJECT) 
	{
		boolean result = false;
		if(OBJECT.equals(null))
		{
			result = true;
		}
		else if(OBJECT instanceof java.lang.String)
		{
			// if true      set to first value : if false set to second value
			result = (OBJECT.equals("") ? true : false);
		}
		else if(OBJECT instanceof java.lang.Object)
		{
			
		}
		else if(OBJECT instanceof java.lang.Object)
		{
			
		}
		else if(OBJECT instanceof java.lang.Object)
		{
			
		}
		else if(OBJECT instanceof java.lang.Object)
		{
			
		}
		
		return result;
	}
}
